package org.eclipse.epsilon.emc.iModelTest;
import org.eclipse.epsilon.eol.EolModule;
import org.eclipse.epsilon.emc.rdbms.dbConnection.SQL2012Connection;
import org.eclipse.epsilon.emc.rdbms.iModel.DBReflexiveModel;
import org.eclipse.epsilon.emc.rdbms.iModel.DBReflexiveModelElement;




public class TestClass 
{

	public static void main(String[] args) throws Exception 
{ 	
 //Database Configuration Settings
  SQL2012Connection myDbTest = new SQL2012Connection("jdbc:sqlserver://","localhost","5551","epsilon","epsilon","epsilon","cursor");
  //Declare and set variables.
  String[] arrTables = myDbTest.getSQLTables();  
  String modelString = "";
  String[] objmap = null;

  //Create a new model.
  DBReflexiveModel rModel = new DBReflexiveModel();
  //Set the Model Name
  rModel.setName(myDbTest.getdatabaseName());
  //Load the model
  rModel.load();
  //Create a new EOL Module.
  EolModule module = new EolModule();

  //Create a simple dummy epsilon program that will use the model we have just created.
  //Need to get a list of tables 
  
  //*********************TO BE DELETED **********************************************
  //For test purposes we will use 1 table so override the arrTables array with the following arraylist  
  String[] dummyArray;
  // allocates memory for 10 integers
  dummyArray = new String[1];
  // initialise first element
  dummyArray[0] = "epsilon.dbo.DatabaseLog";
  arrTables=dummyArray;
  //*******************END OF TO BE DELETED************************************************
  for(int i=0; i < arrTables.length; i++)
  {
     if(arrTables[i] !=null)
	  {
	  objmap = arrTables[i].toString().split("\\.");  // The . character  needs to be escaped as its a special character.  
	  //modelString = modelString.concat(objmap[2]).concat(".all.println(); var ").concat(objmap[2]).concat("=new ").concat(objmap[2]).concat(";").concat(modelString+objmap[2]).concat(".type='").concat(objmap[2]).concat("';").concat(objmap[2]).concat(".type.println();".concat(objmap[2]).concat(".all.println();"));			
	  modelString = modelString.concat(objmap[2]).concat(".all.println();");			
	  }  
    }
  module.parse(modelString); 
  module.getContext().getModelRepository().addModel(rModel);
  module.execute();
}
}


